/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.inventory;


import dao.BaseDaoHibernate;
import java.util.logging.Level;
import model.inventory.AdjMst;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
@Repository
public class AdjMstDao extends BaseDaoHibernate<AdjMst> {
    public boolean saveData(AdjMst domain) {
        Session session = sessionFactory.openSession();
        boolean saved = false;
        try {
            session.beginTransaction();
           
//            for (int i=0; i<domain.getAdjDetails().size(); i++) {
//                domain.getAdjDetails().get(i).getId().setItemId(i);
//            }
            
            domain.setAdjDetails(domain.getAdjDetails());
            sessionFactory.getCurrentSession().saveOrUpdate(domain);
            
            Long orderId = domain.getId();
            for (int i=0; i<domain.getAdjDetails().size(); i++) {
                domain.getAdjDetails().get(i).getId().setId(orderId);
            }

            session.getTransaction().commit();
            saved=true;
        } catch (RuntimeException e) {
            session.getTransaction().rollback(); 
            java.util.logging.Logger.getLogger(AdjMstDao.class.getName()).log(Level.SEVERE, null, e);
        } finally {
            if (session != null) { session.close();}
            return saved;
        }
    }
}
